package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdCapacityChangeStateVO;
import com.yunxi.otd.pojo.OtdCapacityEditVO;
import com.yunxi.otd.pojo.OtdCapacityQueryVO;
import com.yunxi.otd.pojo.OtdCapacityRemoveVO;
import com.yunxi.otd.service.OtdProduceCapacityDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 产能设置 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-08-26
 */
@RestController
@RequestMapping("/admin/otd/capacity")
@Api(tags = "OTD:CAPACITY", description = "产能设置接口")
public class OtdProduceCapacityController {

    /**
     * 产能设置DubboService
     */
    @Autowired
    OtdProduceCapacityDubboService otdProduceCapacityDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "产能查询")
    public ApiResult page(OtdCapacityQueryVO queryVO) {
        if (StringUtils.isEmpty(queryVO.getYearMonth())) {
            return ResponseUtil.fail(-1, "年月不能为空");
        }
        return otdProduceCapacityDubboService.findProduceCapacity(queryVO);
//        return ResponseUtil.ok(otdProduceCapacityDubboService.pageByVo(queryVO, pageNum, pageSize));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增产能设置")
    public ApiResult save(@RequestBody OtdCapacityEditVO editVO) {
        return otdProduceCapacityDubboService.saveOrUpdate(editVO);
    }

    @PostMapping("/edit")
    @ApiOperation(value = "产能编辑")
    public ApiResult edit(@RequestBody OtdCapacityEditVO editVO) {
        return otdProduceCapacityDubboService.editCapacity(editVO);
    }

    @PostMapping("/state")
    @ApiOperation(value = "状态变更")
    public ApiResult changeState(@RequestBody OtdCapacityChangeStateVO editVO) {
        return otdProduceCapacityDubboService.changeState(editVO);
    }

    @GetMapping("/load")
    @ApiOperation(value = "根据ID加载")
    public ApiResult load(String id) {
        return otdProduceCapacityDubboService.load(id);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除")
    public ApiResult remove(@RequestBody List<OtdCapacityRemoveVO> removeVOList) {
        return otdProduceCapacityDubboService.removeByVO(removeVOList);
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出")
    public ApiResult export(OtdCapacityQueryVO queryVO) {
        return ResponseUtil.ok(otdProduceCapacityDubboService.export(queryVO));
    }
}
